package com.jie.erp.springbootjieerp.service.impl;

import com.jie.erp.springbootjieerp.bean.JepRole;
import com.jie.erp.springbootjieerp.bean.UserRole;
import com.jie.erp.springbootjieerp.mapper.JepRoleMapper;
import com.jie.erp.springbootjieerp.mapper.UserRoleMapper;
import com.jie.erp.springbootjieerp.service.JepRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class JepRoleServiceImpl implements JepRoleService {


    @Autowired
    private JepRoleMapper jepRoleMapper;


    @Autowired
    private UserRoleMapper userRoleMapper;


    @Override
    public List<JepRole> getRoleAll() {
        return jepRoleMapper.selectRoleAll();
    }

    @Override
    public JepRole getRoleById(Integer roleId) {
        return jepRoleMapper.selectByPrimaryKey(roleId);
    }

    @Override
    public void granRole(List<UserRole> userRoles,Integer userId) {
        userRoleMapper.deleteByUserId(userId);
        if(userRoles!=null&&userRoles.size()>0){
            for (UserRole userRole:userRoles){
                userRoleMapper.insert(userRole);
            }
        }
    }
}
